package hotel.modal;

import hotel.dao.GoodsDao;
import javafx.beans.property.*;

public class Goods {
	private SimpleIntegerProperty goodsId;	// 物品类型编号
	private SimpleStringProperty name;		// 物品名称
	private SimpleDoubleProperty price;		// 单价
	private SimpleStringProperty describe;	// 物品描述
	protected SimpleBooleanProperty modified;
	
	private void init(GoodsDao gd) {
		if(gd != null) {
			this.goodsId = new SimpleIntegerProperty(gd.getGoodsId());
			this.name = new SimpleStringProperty(gd.getName());
			this.price = new SimpleDoubleProperty(gd.getPrice());
			this.describe = new SimpleStringProperty(gd.getDescribe());
		}else{
			this.goodsId = new SimpleIntegerProperty(0);
			this.name = new SimpleStringProperty("");
			this.price = new SimpleDoubleProperty(0.0);
			this.describe = new SimpleStringProperty("");
		}
		this.modified = new SimpleBooleanProperty(false);
	}
	
	public Goods(GoodsDao gd) {
		init(gd);
	}
	
	public Goods() {
		init(null);
	}
	
	public Object getDao() {
		GoodsDao gd = new GoodsDao();
		gd.setGoodsId(goodsId.get());
		gd.setName(name.get());
		gd.setPrice(price.get());
		gd.setDescribe(describe.get());
		return gd;
	}
	
	public Goods(Goods goods) {
		this.goodsId = new SimpleIntegerProperty(goods.getGoodsId());
		this.name = new SimpleStringProperty(goods.getName());
		this.price = new SimpleDoubleProperty(goods.getPrice());
		this.describe = new SimpleStringProperty(goods.getDescribe());
		this.modified = new SimpleBooleanProperty(false);
	}
	
	public Goods(int goodsId, String name, double price, String describe) {
		this.goodsId = new SimpleIntegerProperty(goodsId);
		this.name = new SimpleStringProperty(name);
		this.price = new SimpleDoubleProperty(price);
		this.describe = new SimpleStringProperty(describe);
		this.modified = new SimpleBooleanProperty(false);
	}
	
	@Override
	public String toString() {
		String str = String.format("GoodsId:%d Name:%s Price:%.2f Describe:%s", 
				goodsId.get(), name.get(), price.get(), describe.get());
		return str;
	}
	
	public final SimpleIntegerProperty goodsIdProperty() {
		return this.goodsId;
	}
	
	public final int getGoodsId() {
		return this.goodsIdProperty().get();
	}
	
	public final void setGoodsId(final int goodsId) {
		this.goodsIdProperty().set(goodsId);
	}
	
	public final SimpleStringProperty nameProperty() {
		return this.name;
	}
	
	public final String getName() {
		return this.nameProperty().get();
	}
	
	public final void setName(final String name) {
		this.nameProperty().set(name);
	}
	
	public final SimpleDoubleProperty priceProperty() {
		return this.price;
	}
	
	public final double getPrice() {
		return this.priceProperty().get();
	}
	
	public final void setPrice(final double price) {
		this.priceProperty().set(price);
	}
	
	public final SimpleStringProperty describeProperty() {
		return this.describe;
	}
	
	public final String getDescribe() {
		return this.describeProperty().get();
	}
	
	public final void setDescribe(final String descirbe) {
		this.describeProperty().set(descirbe);
	}

	public final SimpleBooleanProperty modifiedProperty() {
		return this.modified;
	}
	

	public final boolean isModified() {
		return this.modifiedProperty().get();
	}
	

	public final void setModified(final boolean modified) {
		this.modifiedProperty().set(modified);
	}
}
